From 5bcbc7a3949443ca7a76f9a16c26db3bb9d1b922 Mon Sep 17 00:00:00 2001 From: Simon Budig Date: Tue, 1 May 2012 13:35:58 +0200 Subject: [PATCH] add simple test for float->u8 conversion --- tests/Makefile.am | 1 + tests/floatclamp.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests/floatclamp.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 469a819..b48aee5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -10,6 +10,7 @@ TESTS = \ sanity \ babl_class_name \ extract \ + floatclamp \ types \ palette \ extract \ diff --git a/tests/floatclamp.c b/tests/floatclamp.c new file mode 100644 index 0000000..953b701 --- /dev/null +++ b/tests/floatclamp.c @@ -0,0 +1,70 @@ +/* babl - dynamically extendable universal pixel conversion library. + * Copyright (C) 2005, Øyvind Kolås. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, see + * . + */ + +#include "config.h" +#include +#include +#include +#include "babl.h" + + +#define CHECK_CONV(test_name, componenttype, src_fmt, dst_fmt, src_pix, expected_pix) \ + { \ + const Babl *fish; \ + int i; \ + fish = babl_fish (src_fmt, dst_fmt); \ + if (!fish) \ + { \ + printf (" %s failed to make fish\n", test_name); \ + OK = 0; \ + } \ + for (i = 0; i < sizeof(src_pix)/sizeof(src_pix[0]); i ++) \ + { \ + int c;\ + componenttype result[10]; \ + babl_process (fish, src_pix[i], result, 1); \ + for (c = 0; c < sizeof(expected_pix[i])/sizeof(expected_pix[i][0]); c++) \ + if (result[c] != expected_pix[i][c]) \ + { \ + printf (" %s failed #%i[%i] got %i expected %i\n", test_name, i, c, result[c], expected_pix[i][c]); \ + OK = 0; \ + } \ + } \ + } + +#include + +int +main (int argc, + char **argv) +{ + int OK = 1; + babl_init (); + { + float in[][4] = {{ 0.21582, -0.55, -0.14, 1.0 }}; + unsigned char out[][4] = {{ 55, 0, 0, 255 }}; + + CHECK_CONV("float -> u8", unsigned char, + babl_format("R'G'B'A float"), + babl_format("R'G'B'A u8"), + in, out); + } + + babl_exit (); + return !OK; +} -- 2.30.2